#include "cdnf.h"
using cdnf::DNF;
using cdnf::CDNF;
CDNF::CDNF():degeneratedValue(true){}
bool CDNF::getValue(bool* valuation){
	if (isDegenerated())
			return degeneratedValue;
	for (unsigned int i=0;i<dnfs.size();i++) {
		if (!dnfs[i].getValue(valuation))
			return false;
	}
	return true;
}
bool CDNF::getValue(Valuation& valuation){
	if (isDegenerated())
			return degeneratedValue;
	for (unsigned int i=0;i<dnfs.size();i++) {
		if (!dnfs[i].getValue(valuation))
			return false;
	}
	return true;
}
std::vector<DNF>& CDNF::getDnfs(){
	return this->dnfs;
}
void CDNF::addDNF(DNF& dnf){
	this->dnfs.push_back(dnf);
}
DNF& CDNF::getDNF(int index){
	return this->dnfs.at(index);
}
void CDNF::setDNF(int index, DNF& dnf){
	this->dnfs[index]=dnf;
}
bool CDNF::isDegenerated(){
	if (dnfs.size() == 0)
			return true;
	for (unsigned int i=0;i<(dnfs.size());i++) {
			if (dnfs[i].isDegenerated() && !dnfs[i].getDegeneratedValue()) {
				degeneratedValue = false;
				return true;
			}
		}
		return false;
}
void CDNF::setDegeneratedValue(bool degeneratedValue){
	this->degeneratedValue = degeneratedValue;
}
bool CDNF::getDegeneratedValue() const{
	return this->degeneratedValue;
}
bool CDNF::isTrue(){
	return this->isDegenerated() && this->getDegeneratedValue();
}
bool CDNF::isFalse(){
	return this->isDegenerated() && !this->getDegeneratedValue();
}
